
package com.cuit.xsc.weishare.activity;



import java.util.HashMap;
import java.util.Map;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.cuit.xsc.weishare.R;
import com.cuit.xsc.weishare.logic.MainService;
import com.cuit.xsc.weishare.logic.Task;
import com.cuit.xsc.weishare.model.User;

public class SelfInfoAct extends BaseActivity implements OnClickListener
{
	private View progresView;
	
	private TextView titleTv;
	
	private ImageView ivPortrait; //头像
	private ImageView ivGental;   //性别
	private Button bnEdit;        //编辑
	
	private TextView tvVipContent;
	private TextView tvAddressContent;
	private TextView tvSelfIntroduceContent;
	
	private TextView tvAttentionCount;
	private TextView tvWeiboCount;
	private TextView tvFansCount;
	private TextView tvTopicCount;
	
	private User user;
	private Bitmap bitmap;
	
	
	
	
	


	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.user_info);
		init();
		titleTv.setText("个人信息");
		Task task = new Task(Task.GET_USER, null);
		MainService.addTask(task);
		showProgress();
	}
	
	
	private void init()
	{
		titleTv = (TextView) findViewById(R.id.txt_wb_title);
		ivPortrait = (ImageView) findViewById(R.id.ivPortrait);
		ivGental = (ImageView) findViewById(R.id.ivGental);
		bnEdit = (Button) findViewById(R.id.bnEdit);
		tvVipContent = (TextView) findViewById(R.id.tvSinaVip_content);
		tvAddressContent = (TextView) findViewById(R.id.tvAddress2_content);
		tvSelfIntroduceContent = (TextView) findViewById(R.id.tvSelf_Introduce_content);
		tvAttentionCount = (TextView) findViewById(R.id.tvAttention_count);
		tvWeiboCount = (TextView) findViewById(R.id.tvWeibo_count);
		tvFansCount = (TextView) findViewById(R.id.tvFans_count);
		tvTopicCount = (TextView) findViewById(R.id.tvTopic_count);
	}
	
	
	
	@Override
	public void refresh(Object... param)
	{
		
		int flag = ((Integer) param[0]).intValue();
		switch (flag)
		{
		    case Task.GET_USER:
			 user = (User) param[1];
			if (user != null && user.getHead() != null)
			{
				
				Map map = new HashMap<String, String>();
				map.put("url", user.getHead());
				Task task = new Task(Task.GET_SELFINFO_HEAD, map);
				MainService.addTask(task);
				user.getHead();
			}
			else
			{
				dismissProgress();
			}
			
			break;
			case Task.GET_SELFINFO_HEAD:
				
				dismissProgress();
				bitmap = (Bitmap) param[1];
				showUserInfo(user);	
		    break;

		default:
			break;
		}
	}
	
	public void showUserInfo(User user)
	{
//		ivPortrait
	//	ivGental
		//bnEdit
		
		if (bitmap != null)
		{
			ivPortrait.setImageBitmap(bitmap);
		}
		
		if (user.getGender().equals("m"))
		{
			ivGental.setImageDrawable(getResources().getDrawable(R.drawable.icon_male));
		}
		else
		{
			ivGental.setImageDrawable(getResources().getDrawable(R.drawable.icon_female));
		}
		
		
		if (user != null)
		{
			if (user.isVip())
			{
				tvVipContent.setText("是");
			}
			else
			{
				tvVipContent.setText("否");
			}
			
			tvAddressContent.setText(user.getLocation());
			tvSelfIntroduceContent.setText(user.getName());
			tvAttentionCount.setText(user.getFollowersCount()+"");
			tvWeiboCount.setText(user.getStatusesCount()+"");
			tvFansCount.setText(user.getFollowersCount()+"");
			tvTopicCount.setText(user.getFavouritesCount()+"");
		}
		
	}


	@Override
	public void onClick(View v)
	{
		switch (v.getId())
		{
		case R.id.bnEdit:
			
			break;

		default:
			break;
		}
		
	}
	
	
	
}
